<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>18.迭代器</title>
</head>
<body>
    <script>
        //声明一个数组
        const xiyou = ['唐僧','孙悟空','猪八戒','沙僧']
        //使用for...of 遍历数组 类似java正确for循环
        for(let v of xiyou){
            console.log(v)
        }

        let iterator = xiyou[Symbol.iterator]();
        //调用对象的next方法
        console.log(iterator.next()); //{value: '唐僧', done: false}
        console.log(iterator.next()); //{value: '孙悟空', done: false}
        console.log(iterator.next()); //{value: '猪八戒', done: false}
        console.log(iterator.next()); //{value: '沙僧', done: false}  
        console.log(iterator.next()); //{value: undefined, done: true}

        // done属性表示遍历状态 true表示遍历完成
    </script>
</body>
</html>